/* Copyright Thanh-Trung Pham, JAIST, 2013 */

package jp.ac.jaist.input;

import jp.ac.jaist.InternalActivityType;
import jp.ac.jaist.InternalActivityType.OccurringFailureType;

/**
 *
 * @author Thanh-Trung Pham
 */
public class RMPInternalActivityWrapper {

    double[] m_oFailureProbabilities;

    /**
     * The constructor.
     */
    public RMPInternalActivityWrapper() {
        initialize();
    }

    /**
     * The constructor.
     * @param internalActivity an internal activity.
     */
    public RMPInternalActivityWrapper(InternalActivityType internalActivity) {
        initialize();

        OccurringFailureType[] ocurringFailureTypes = internalActivity.getOccurringFailureTypeArray();

        double dTotalFailureProbability = 0.0;
        for (OccurringFailureType ocurringFailureType : ocurringFailureTypes) {
            String strForFailureType = ocurringFailureType.getForFailureType();

            int iFailureTypeIndex = RMPInputModelManager.getInstance().getFailureTypeIndex(strForFailureType);
            double dFailureProbability = ocurringFailureType.getProbability();
            m_oFailureProbabilities[iFailureTypeIndex] = dFailureProbability;

            dTotalFailureProbability += dFailureProbability;
        }

        m_oFailureProbabilities[0] = 1.0 - dTotalFailureProbability;
    }

    /**
     * Initialize.
     */
    private void initialize() {
        int iNumberOfFailureTypes = RMPInputModelManager.getInstance().getNumberOfFailureTypes();
        m_oFailureProbabilities = new double[iNumberOfFailureTypes];
        for (int i = 0; i < iNumberOfFailureTypes; i++) {
            m_oFailureProbabilities[i] = 0.0;
        }
    }

    /**
     * Get the success probability.
     * @return the success probability.
     */
    public double getSp() {
        return m_oFailureProbabilities[0];
    }

    /**
     * Set the success probability.
     * @param successProbability the success probability.
     */
    public void setSp(double successProbability) {
        m_oFailureProbabilities[0] = successProbability;
    }

    /**
     * Get the failure probability of a failure type with a given index.
     * @param failureTypeIndex the failure type index.
     * @return the failure probability of a failure type with a given index.
     */
    public double getFp(int failureTypeIndex) {
        return m_oFailureProbabilities[failureTypeIndex];
    }

    /**
     * Set the failure probability for a failure type with a given index.
     * @param failureTypeIndex the failure type index.
     * @param failureProbability he failure probability .
     */
    public void setFp(int failureTypeIndex, double failureProbability) {
        m_oFailureProbabilities[failureTypeIndex] = failureProbability;
    }

    /**
     * Get the failure probability of a failure type with a given failure type name.
     * @param failureTypeName the failure type name.
     * @return the failure probability of a failure type with a given failure type name.
     */
    public double getFp(String failureTypeName) {
        return m_oFailureProbabilities[RMPInputModelManager.getInstance().getFailureTypeIndex(failureTypeName)];
    }
}
